package com.robot.common.core.tool;

import lombok.Data;


/**
 * @Description: 统一返回格式
 * @author:lyq
 * @Date:2020-11-25 14:29
 */
@Data
public class R<T> {

    //Map<String,Object> map = new HashMap<>();

    //Map<String,Object> map;

    private T data;

    private Integer code = 200;

    private String msg = "操作成功";

    private Boolean isSuccess = true;

    public static R fail(String msg){
        R t = new R();
        t.setCode(400);
        t.setIsSuccess(false);
        t.setMsg(msg);
        return t;
    }

    public static R status(Boolean status){
        R t = new R();
        t.setCode(400);
        t.setIsSuccess(status);
        if(status){
            t.setMsg("操作成功");
        }else {
            t.setMsg("操作失败");
        }

        return t;
    }

    public static R success(String msg){
        R t = new R();
        t.setMsg(msg);
        return t;
    }

    public static R data(Object data){
       R r = new R();
       r.setData(data);
       return r;
    }
}
